package com.eagledata.project.business.memberInfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.eagledata.project.business.memberInfo.domain.MemberInfo;
import com.eagledata.project.business.memberInfo.service.IMemberInfoService;
import com.eagledata.framework.web.controller.BaseController;
import com.eagledata.framework.web.page.TableDataInfo;
import com.eagledata.framework.web.domain.Message;

/**
 * 会员 信息操作处理
 * 
 * @author eagledata
 * @date 2018-06-25
 */
@Controller
@RequestMapping("/business/memberInfo")
public class MemberInfoController extends BaseController
{
    private String prefix = "business/memberInfo";
	
	@Autowired
	private IMemberInfoService memberInfoService;
	
	@RequestMapping()
	@RequiresPermissions("business:memberInfo:view")
	public String memberInfo() {
	    return prefix + "/memberInfo";
	}
	
	/**
	 * 查询会员列表
	 */
	@RequiresPermissions("business:memberInfo:list")
	@RequestMapping("/list")
	@ResponseBody
	public TableDataInfo list(MemberInfo memberInfo) {
		startPage();
        List<MemberInfo> list = memberInfoService.selectMemberInfoList(memberInfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增会员
	 */
	@RequiresPermissions("business:memberInfo:add")
	@RequestMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 修改会员
	 */
	@RequiresPermissions("business:memberInfo:edit")
	@RequestMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, Model model) {
		MemberInfo memberInfo = memberInfoService.selectMemberInfoById(id);
		model.addAttribute("memberInfo", memberInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 保存会员
	 */
	@RequiresPermissions("business:memberInfo:save")
	@RequestMapping("/save")
	@ResponseBody
	public Message save(MemberInfo memberInfo) {
		if (memberInfoService.saveMemberInfo(memberInfo) > 0){
			return Message.success();
		}
		return Message.error();
	}
	
	/**
	 * 删除会员
	 */
	@RequiresPermissions("business:memberInfo:remove")
	@RequestMapping( "/remove/{id}")
	@ResponseBody
	public Message remove(@PathVariable("id") Integer id) {
		if (memberInfoService.deleteMemberInfoById(id) > 0)
		{
		    return Message.success();
		}
		return Message.error();
	}
	
	/**
	 * 批量删除会员
	 */
	@RequiresPermissions("business:memberInfo:batchRemove")
	@RequestMapping( "/batchRemove")
	@ResponseBody
	public Message remove(@RequestParam("ids[]") Integer[] ids) {
		int rows = memberInfoService.batchDeleteMemberInfo(ids);
		if (rows > 0)
        {
            return Message.success();
        }
        return Message.error();
	}
	
	
	/**
	 *
	 * @Description		:  用户积分操作
	 * @author    		:  XueMeng
	 * @date      		:  2018年6月26日 下午1:14:30
	 * @return    		:  Message
	 * @参数说明	  		:  @param id
	 * @参数说明	  		:  @param point
	 * @参数说明	  		:  @return
	 *
	 */
	@RequestMapping( "/addPointByMember")
	@ResponseBody
	public Integer addPointByMember(@RequestParam("id") Integer id, @RequestParam("point")Integer addPoint) {
		MemberInfo memberInfo = memberInfoService.selectMemberInfoById(id);
		Integer point = memberInfo.getPoint();
		point += addPoint;
		Integer result = memberInfoService.updateMemberInfo(memberInfo);
        return result;
	}
	
}
